package logic

import (
	"context"
	"regi/models"
	"regi/regirpc/internal/svc"
	"regi/regirpc/regirpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegiAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRegiAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegiAddLogic {
	return &RegiAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加
func (l *RegiAddLogic) RegiAdd(in *regirpc.RegiAddRequest) (*regirpc.RegiAddResponse, error) {
	// todo: add your logic here and delete this line

	regi := &models.Regi{
		Name:     in.Name,
		HospName: in.HospName,
		DepName:  in.DepName,
		Tel:      in.Tel,
	}

	if err := regi.RegiAdd(models.DB); err != nil {
		return nil, err
	}

	return &regirpc.RegiAddResponse{
		RegiId: int64(regi.ID),
	}, nil
}
